//
//  ZYCTourRecordMarkBottomView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/26.
//

#import "ZYCTourRecordMarkBottomView.h"
#import "EMTextView.h"
#define MaxCount 40

@interface ZYCTourRecordMarkBottomView ()<UITextViewDelegate>

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) EMTextView *contentTextView;

@end
@implementation ZYCTourRecordMarkBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =HEX_RGB(kBgWhiteColor);
        [self addSubview:self.titleLabel];
        [self addSubview:self.line];
        [self addSubview:self.contentTextView];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self).offset(14.0f);
        }];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(14.0f);
            make.right.equalTo(self).offset(-14.0f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.height.mas_equalTo(1.0f);
        }];
        
        [self.contentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.line.mas_bottom).offset(25.0f);
            make.left.equalTo(self).offset(14.0f);
            make.right.equalTo(self).offset(-14.0f);
            make.bottom.equalTo(self);
        }];
    }
    return self;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithString:@"说明:" Font:kCustomFont(@"PingFangSC-Light", 16.0f) titleColor:HEX_RGB(@"#999999") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EBEBEB");
    }
    return _line;
}

- (EMTextView *)contentTextView {
    if (!_contentTextView) {
        _contentTextView = [[EMTextView alloc] init];
        _contentTextView.delegate = self;
        _contentTextView.placeholder = @"请输入您的说明";
        _contentTextView.font = kCustomFont(@"PingFangSC-Regular", 16.0f);
    }
    return _contentTextView;
}


-(NSString *)remarkContent{
    return self.contentTextView.text;
}

#pragma mark - UITextViewDelegate

/// 用此代理方法限制字数，因为在iOS9中选择联想词不会走(textView:shouldChangeTextInRange:replacementText:)这个方法
- (void)textViewDidChange:(UITextView *)textView {
    // textView.markedTextRange == nil 说明当前不是正在打字的高亮状态
    if (textView.markedTextRange == nil) {
        if (textView.text.length > MaxCount) {
            textView.text = [textView.text substringToIndex:MaxCount];
        }
    }
}

@end
